package com.sgb.kjwl.view.ui.adapter.transport;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.transport.FilterTabEntity;

import java.util.List;

/**
 * @author: 杨畔
 * @date: 3/1/21 10:20 AM
 * @Description: 物流筛选tab适配器
 */
public class LogisticsFilterTabAdapter extends BaseQuickAdapter<FilterTabEntity, BaseViewHolder> {
    public static final int NORMAL = 0;
    public static final int EXPAND = 1;
    public static final int SELECTED = 2;

    public LogisticsFilterTabAdapter(@Nullable List<FilterTabEntity> data) {
        super(R.layout.item_logistics_filter_tab, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, FilterTabEntity item) {
        switch (item.getTabStatus()) {
            case NORMAL://普通状态
                helper.setText(R.id.tv_filter_tab_title, item.getTitle())
                        .setBackgroundRes(R.id.cl_filter_tab_title, R.drawable.shape_gray_coner)
                        .setImageResource(R.id.iv_filter_tab_title, R.mipmap.ic_down_arrow_n)
                        .getView(R.id.tv_filter_tab_title).setSelected(false);
                break;
            case EXPAND://展开状态
                helper.setText(R.id.tv_filter_tab_title, item.getTitle())
                        .setBackgroundRes(R.id.cl_filter_tab_title, R.drawable.shape_gray_coner)
                        .setImageResource(R.id.iv_filter_tab_title, R.mipmap.ic_up_arrow_n)
                        .getView(R.id.tv_filter_tab_title).setSelected(false);
                break;
            case SELECTED://选中状态
                helper.setText(R.id.tv_filter_tab_title, item.getTitle())
                        .setBackgroundRes(R.id.cl_filter_tab_title, R.drawable.shape_theme_coner)
                        .setImageResource(R.id.iv_filter_tab_title, R.mipmap.ic_down_arrow)
                        .getView(R.id.tv_filter_tab_title).setSelected(true);
                break;
        }
    }

    /**
     * 设置tab状态
     */
    public void setTabStatus(int position, int status) {
        mData.get(position).setTabStatus(status);
        notifyDataSetChanged();
    }

    /**
     * 设置tab标题
     */
    public void setTabTitle(int position, String title) {
        mData.get(position).setTitle(title);
        notifyDataSetChanged();
    }

    /**
     * 设置tab状态和标题
     */
    public void setTabStatusAndTitle(int position, int status, String title) {
        FilterTabEntity filterTabEntity = mData.get(position);
        filterTabEntity.setTabStatus(status);
        filterTabEntity.setTitle(title);
        notifyDataSetChanged();
    }
}
